<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是通信协议——串口通信相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="通信协议-02-串口通信">
<meta property="og:url" content="https://sumumm.github.io/post/22871ce2.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是通信协议——串口通信相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20230501214655350.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918133144245.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918134315229.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918134419265.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918135327195.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918135941268.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918140008443.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918140427051.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20230501215603857.png">
<meta property="article:published_time" content="2022-08-22T07:41:53.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.060Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="通信协议">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20230501214655350.png">


<link rel="canonical" href="https://sumumm.github.io/post/22871ce2.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/22871ce2.html","path":"post/22871ce2.html","title":"通信协议-02-串口通信"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>通信协议-02-串口通信 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1%E7%AE%80%E4%BB%8B"><span class="nav-text">一、串口通信简介</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%B2%E5%8F%A3%E7%AE%80%E4%BB%8B"><span class="nav-text">1. 串口简介</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%8E%A5%E5%8F%A3%E6%A0%87%E5%87%86%EF%BC%9F"><span class="nav-text">2. 接口标准？</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE"><span class="nav-text">二、串口通信协议</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1%E7%89%A9%E7%90%86%E5%B1%82%E8%BF%9E%E6%8E%A5"><span class="nav-text">1.串口通信物理层连接</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E7%94%B5%E5%B9%B3%E6%A0%87%E5%87%86"><span class="nav-text">2.电平标准</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%B8%B8%E8%A7%81%E6%8E%A5%E5%8F%A3"><span class="nav-text">3.常见接口</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1%E5%B8%B8%E8%A7%81%E7%9A%84-TTL-%E7%94%B5%E5%B9%B3%E6%8E%A5%E5%8F%A3"><span class="nav-text">3.1常见的 TTL 电平接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2%E5%B8%B8%E8%A7%81%E7%9A%84-RS-232-%E6%8E%A5%E5%8F%A3"><span class="nav-text">3.2常见的 RS-232 接口</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E4%BC%A0%E8%BE%93%E5%8D%8F%E8%AE%AE"><span class="nav-text">4.传输协议</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E6%B3%A2%E7%89%B9%E7%8E%87"><span class="nav-text">5.波特率</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81UART%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1"><span class="nav-text">三、UART串口通信</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%A1%AC%E4%BB%B6%E8%BF%9E%E6%8E%A5"><span class="nav-text">1.硬件连接</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-UART-%E5%B8%A7%E6%A0%BC%E5%BC%8F"><span class="nav-text">2. UART 帧格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%8F%91%E9%80%81%E4%B8%80%E4%B8%AA%E5%AD%97%E8%8A%82%E6%95%B0%E6%8D%AE"><span class="nav-text">3. 发送一个字节数据</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/22871ce2.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="通信协议-02-串口通信 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          通信协议-02-串口通信
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-08-22 15:41:53" itemprop="dateCreated datePublished" datetime="2022-08-22T15:41:53+08:00">2022-08-22</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/" itemprop="url" rel="index"><span itemprop="name">03通信协议</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3.6k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>13 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是通信协议——串口通信相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向  </td><td align="center">参考原文</td></tr>    <tr><td align="left">驱动开发指南</td><td align="left"><a href="http://47.111.11.73/docs/boards/arm-linux/zdyz-i.mx6ull.html#i-mx6ull-linux" target="_blank">i.MX6ULL Linux阿尔法开发板资料 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">STM32开发指南</td><td align="left"><a href="http://www.openedv.com/docs/boards/stm32/zdyz_stm32f103_warship.html#id3" target="_blank">STM32F1开发指南-库函数版本_V3.3 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">野火STM32开发指南</td><td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103badao/std/zh/latest/book/communication.html" target="_blank">STM32库开发实战指南——基于野火霸道开发板 文档 (embedfire.com) <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">---</td>        <td align="left">--- <a href="" target="_blank">  <i class="fa fa-external-link-alt"></i></a></td>      </tr></table>
              </div>
            </details>

<h1 id="一、串口通信简介"><a href="#一、串口通信简介" class="headerlink" title="一、串口通信简介"></a><font size=3>一、串口通信简介</font></h1><h2 id="1-串口简介"><a href="#1-串口简介" class="headerlink" title="1. 串口简介"></a><font size=3>1. 串口简介</font></h2><p>串口通讯(Serial Communication)是一种设备间非常常用的串行通讯方式，因为它简单便捷，因此大部分电子设备都支持该通讯方式。串口全称叫做串行接口，通常也叫做 COM 接口，串行接口指的是数据一个一个的顺序传输，通信线路简单。使用两条线即可实现双向通信，一条用于发送，一条用于接收。串口通信距离远，但是速度相对会低，串口是一种很常用的工业接口。我们常用串行外设接口有UART和USART两种：</p>
<ul>
<li><p>UART：UART 全称是 Universal Asynchronous Receiver&#x2F;Trasmitter，也就是异步串行收发器。</p>
</li>
<li><p>USART：USART 的全称是 Universal Synchronous&#x2F;Asynchronous Receiver&#x2F;Transmitter，也就是同步&#x2F;异步串行收发器。相比 UART 多了一个同步的功能，在硬件上体现出来的就是多了一条时钟线。 一般 USART 是可以作为 UART 使用的，也就是不使用其同步的功能 。</p>
</li>
</ul>
<p>相对而言，UART我们用的更多，本篇笔记主要是关于UART通信的相关内容。</p>
<h2 id="2-接口标准？"><a href="#2-接口标准？" class="headerlink" title="2. 接口标准？"></a><font size=3>2. 接口标准？</font></h2><p>说到串口，经常提到TTL、 RS232、 RS422、 RS485，简单的说，就是为了适应不同的环境条件，使用了不同的<strong>电平标准</strong>。假如微处理器和板载的蓝牙透传模块通信时，一般就使用TTL电平，引脚直接连接即可。假如微处理器在工业现场，需要连接一个几十米外的装置，则应该考虑将TTL电平转为RS232、 RS422、 RS485。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20230501214655350.png" alt="image-20230501214655350" style="zoom: 20%;" />

<p>下表是几个通信接口标准总结，可以发现为了加大传输距离，依次尝试了增加电压、差分传输等方式。  </p>
<table>
<thead>
<tr>
<th>通信接口</th>
<th>电平标准</th>
<th>特点</th>
</tr>
</thead>
<tbody><tr>
<td>TTL</td>
<td>逻辑1： 2.4V至5V 逻辑0： 0V至0.4V</td>
<td>无需额外电路，直接引脚直连即可</td>
</tr>
<tr>
<td>RS232</td>
<td>逻辑1： -3V至-15V 逻辑0： 3V至15V</td>
<td>需要电平转换电路，传输距离最大约15米</td>
</tr>
<tr>
<td>RS422&#x2F;RS485</td>
<td>逻辑1：两线压差为2V至6V 逻辑0：两线压差-2V至-6V</td>
<td>需要电平转换电路，传输距离最大约1200米</td>
</tr>
</tbody></table>
<h1 id="二、串口通信协议"><a href="#二、串口通信协议" class="headerlink" title="二、串口通信协议"></a><font size=3>二、串口通信协议</font></h1><h2 id="1-串口通信物理层连接"><a href="#1-串口通信物理层连接" class="headerlink" title="1.串口通信物理层连接"></a><font size=3>1.串口通信物理层连接</font></h2><p>串口通讯的物理层（就是硬件连接）有很多标准及变种，常见的就是 RS-232 标准，RS-232标准主要规定了信号的用途、通讯接口以及信号的电平标准。使用RS-232标准的串口设备间常见的通讯结构如下图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918133144245.png" alt="image-20220918133144245" style="zoom:50%;" />



<h2 id="2-电平标准"><a href="#2-电平标准" class="headerlink" title="2.电平标准"></a><font size=3>2.电平标准</font></h2><p>根据通讯使用的电平标准不同，串口通讯可分为TTL标准及RS-232标准：</p>
<table>
    <tr><td align="left">通信标准</td><td align="left">电平标准（发送端）</td></tr>
    <tr><td align="left" rowspan=2>5V TTL</td><td align="left">逻辑1：2.4V ~ 5.0V</td></tr>
    <tr><td align="left">逻辑0：0V ~ 0.5V  </td></tr>
    <tr><td align="left" rowspan=2>RS-232</td><td align="left">逻辑1：-15V ~ -3V </td></tr>
    <tr><td align="left">逻辑0：+3V ~ +15V </td></tr>
</table>
我们知道常见的电子电路中常使用TTL的电平标准，理想状态下，使用5V表示二进制逻辑1，使用0V表示逻辑0； 对于RS-232，为了增加串口通讯的远距离传输及抗干扰能力，它使用-15V表示逻辑1，+15V表示逻辑0。 

<h2 id="3-常见接口"><a href="#3-常见接口" class="headerlink" title="3.常见接口"></a><font size=3>3.常见接口</font></h2><h3 id="3-1常见的-TTL-电平接口"><a href="#3-1常见的-TTL-电平接口" class="headerlink" title="3.1常见的 TTL 电平接口"></a><font size=3>3.1常见的 TTL 电平接口</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918134315229.png" alt="image-20220918134315229" style="zoom: 25%;" />

<p>这就是一个 USB 转 TTL 模块， TTL 接口部分有 VCC、 GND、 RXD、 TXD、RTS 和 CTS。 RTS 和 CTS 基本用不到，使用的时候通过杜邦线和其他模块的 TTL 接口相连即可。  </p>
<h3 id="3-2常见的-RS-232-接口"><a href="#3-2常见的-RS-232-接口" class="headerlink" title="3.2常见的 RS-232 接口"></a><font size=3>3.2常见的 RS-232 接口</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918134419265.png" alt="image-20220918134419265" style="zoom: 33%;" />

<p>RS-232 电平需要 DB9 接口 （也就是常说的 COM口）。现在的电脑很多都没有 DB9 接口了，取而代之的是 USB 接口，所以就催生出了很多 USB 转串口 TTL 芯片，比如 CH340、PL2303 等。通过这些芯片就可以实现串口 TTL 转 USB。  </p>
<ul>
<li>RS-232接口缺陷</li>
</ul>
<p>（1） 接口的信号电平值较高（+&#x2F;-15V)，易损坏接口电路的芯片。</p>
<p>（2） 传输速率较低，在异步传输时，波特率为 20Kbps。</p>
<p>（3） 接口使用一根信号线和一根信号返回线而构成共地的传输形式，这种共地传输容易产生共模干扰，所以抗噪声干扰性弱。</p>
<p>（4） 传输距离有限，最大传输距离标准值为50英尺，实际上也只能用在50米左右。</p>
<h2 id="4-传输协议"><a href="#4-传输协议" class="headerlink" title="4.传输协议"></a><font size=3>4.传输协议</font></h2><p>串口通讯的数据包由发送设备通过自身的 TXD 接口传输到接收设备的 RXD 接口。在串口通讯的协议层中， 规定了数据包的内容，它由起始位、主体数据、校验位以及停止位组成，通讯双方的数据包格式要约定一致才能正常收发数据，串口数据包基本组成如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918135327195.png" alt="image-20220918135327195" style="zoom:50%;" />

<h2 id="5-波特率"><a href="#5-波特率" class="headerlink" title="5.波特率"></a><font size=3>5.波特率</font></h2><p>异步通信中由于没有时钟信号(如前面讲解的 DB9 接口中是没有时钟信号的)， 所以两个通讯设备之间需要约定好波特率，即每个码元的长度，以便对信号进行解码，波特率的单位为：bps（bit per second）即每秒钟传送的 bit 的数量。例如上边传输协议一节的表示串口数据包基本组成的图中用虚线分开的每一格就是代表一个码元。常见的波特率为4800、9600、38400和115200等。</p>
<p>例如：115200bps、指每秒传送115200位。通信双方必须设置同样的同学速率才能正常通信</p>
<h1 id="三、UART串口通信"><a href="#三、UART串口通信" class="headerlink" title="三、UART串口通信"></a><font size=3>三、UART串口通信</font></h1><h2 id="1-硬件连接"><a href="#1-硬件连接" class="headerlink" title="1.硬件连接"></a><font size=3>1.硬件连接</font></h2><p>UART接口一般连接情况如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918135941268.png" alt="image-20220918135941268" style="zoom: 33%;" />

<ul>
<li><p>RXD：数据输入引脚，数据接收。</p>
</li>
<li><p>TXD：数据发送引脚，数据发送。</p>
</li>
</ul>
<p>有的可能还需要转换一下电平：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918140008443.png" alt="image-20220918140008443" style="zoom: 33%;" />

<h2 id="2-UART-帧格式"><a href="#2-UART-帧格式" class="headerlink" title="2. UART 帧格式"></a><font size=3>2. UART 帧格式</font></h2><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20220918140427051.png" alt="image-20220918140427051" style="zoom: 33%;" />

<ul>
<li><strong>空闲位</strong></li>
</ul>
<p>数据线在空闲状态的时候为逻辑“1”状态，也就是高电平，表示没有数据线空闲，没有数据传输。</p>
<ul>
<li><strong>起始位</strong></li>
</ul>
<p>当要传输数据的时候先传输一个逻辑“0”，也就是将数据线拉低，表示开始数据传输。</p>
<ul>
<li><strong>数据位</strong></li>
</ul>
<p>数据位就是实际要传输的数据，数据位数可选择 5~8 位，我们一般都是按照字节传输数据的，一个字节 8 位，因此数据位通常是 8 位的。低位在前，先传输，高位最后传输。</p>
<ul>
<li><strong>奇偶校验位</strong></li>
</ul>
<p>在有效数据之后，有一个可选的数据校验位。由于数据通信相对更容易受到外部干扰导致传输数据出现偏差， 可以在传输过程加上校验位来解决这个问题。校验方法有奇校验(odd)、偶校验(even)、0校验(space)、1校验(mark)以及无校验(noparity)，可以不使用校验位。</p>
<p>（1）奇校验与偶校验：奇校验要求有效数据和校验位中“1”的个数为奇数，比如一个8位长的有效数据为：01101001，此时总共有4个“1”， 为达到奇校验效果，校验位为“1”，最后传输的数据将是8位的有效数据加上1位的校验位总共9位。偶校验与奇校验要求刚好相反，要求帧数据和校验位中“1”的个数为偶数， 比如数据帧：11001010，此时数据帧“1”的个数为4个，所以偶校验位为“0”。</p>
<p>（2）0校验与1校验：0校验是不管有效数据中的内容是什么，校验位总为“0”。1校验是校验位总为“1”。</p>
<ul>
<li><strong>停止位</strong></li>
</ul>
<p>数据传输完成标志位，数据线变回逻辑”1”。停止位的位数可以选择 1 位、 1.5 位或 2 位高电平，一般都选择 1 位停止位。</p>
<ul>
<li><strong>波特率</strong></li>
</ul>
<p>波特率就是 UART 数据传输的速率，也就是每秒传输的数据位数，一般选择 9600、38400、 115200 等。  </p>
<h2 id="3-发送一个字节数据"><a href="#3-发送一个字节数据" class="headerlink" title="3. 发送一个字节数据"></a><font size=3>3. 发送一个字节数据</font></h2><p>怎么发送一字节数据，比如“ A ”？ “ A ” 的ASCII值是0x41， 二进制就是0100 0001，怎样把这8位数据发送给对方呢？  </p>
<p>（1）双方约定好波特率、数据格式(数据位个数、停止位个数、是否使用校验位、奇校验还是偶校验)，假设数据位是8，停止位是1，校验位是1；</p>
<p>（2）初始电平为逻辑1； </p>
<p>（3）发送方输出逻辑0，并保持1位的时间；接收方检测到逻辑0，就知道对方准备发送数据了；  </p>
<p>（4）发送方根据数据的bit 0设置引脚电平，并保持1位的时间；接收方读取引脚电平，得到bit 0；</p>
<p>（5）发送方根据数据的bit 1设置引脚电平，并保持1位的时间；接收方读取引脚电平，得到bit 1；</p>
<p>（6）以此类推，发出8位数据；</p>
<p>（7）发送方计算出校验值，设置引脚，并保持1位的时间；接收方读取引脚电平，得到校验值；注意，这步可以省略；</p>
<p>（8）发送方输出逻辑1，并保持1位的时间；接收方读取引脚电平， 直到数据传输结束；  </p>
<p>整个过程的信号的波形图如下：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/03%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE-02-%E4%B8%B2%E5%8F%A3%E9%80%9A%E4%BF%A1/img/image-20230501215603857.png" alt="image-20230501215603857" style="zoom: 50%;" />

 

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/22871ce2.html">通信协议-02-串口通信</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2022年08月22日 - 15:41</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/22871ce2.html" title="通信协议-02-串口通信">https://sumumm.github.io/post/22871ce2.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/%E9%80%9A%E4%BF%A1%E5%8D%8F%E8%AE%AE/" rel="tag"><i class="fa fa-tag"></i> 通信协议</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/1c55a2ac.html" rel="prev" title="通信协议-03-I2C通信">
                  <i class="fa fa-angle-left"></i> 通信协议-03-I2C通信
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/25ce70ee.html" rel="next" title="通信协议-01-通信的基本概念">
                  通信协议-01-通信的基本概念 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">false</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
